package com.itheima.controller;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Component
public class ExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        ModelAndView modelAndView=new ModelAndView();
        if( e instanceof NullPointerException){
            modelAndView.addObject("msg","空指针异常");
        }else {
            modelAndView.addObject("msg","未知的异常");
        }
      modelAndView.setViewName("success.jsp");
        return modelAndView;
    }
}
